<?php
	

defined('_JEXEC') or die();

jimport( 'joomla.application.component.view' );

class NBEventMapsViewGestionLieux extends JView
{
	function display($tpl = null)
	{
		$mainframe 	=& JFactory::getApplication(); 
		$option    	=  JRequest::getCMD('option', ''); 
		$doc 		=& JFactory::getDocument();

		
		$user		= JFactory::getUser();
		$userId		= $user->get('id');

		$params = clone($mainframe->getParams('com_nbeventmap'));
		$niveau_utilisateur_ok=$params->get('nbeventmap_acces_groups');
		
		
		if ($userId < $niveau_utilisateur_ok) {
			  JResponse::setHeader('HTTP/1.0 403',true);
              JError::raiseWarning( 403, JText::_('JERROR_ALERTNOAUTHOR') );
			return;
		}

		 
		$doc->addCustomTag ('<link rel="stylesheet" href="'.$this->baseurl.'/components/com_nbeventmap/views/editlieux/css/icon.css" type="text/css" media="screen" />');
		$doc->addCustomTag ('<link rel="stylesheet" href="'.$this->baseurl.'/components/com_nbeventmap/views/editlieux/css/general.css" type="text/css" media="screen" />');

		
		$items		= & $this->get( 'Data');
		$total		= & $this->get( 'Total');
		$pageNav 	= & $this->get( 'Pagination' );

		$filtrevilles = array();
		$filtrevilles[] = JHTML::_('select.option', '-- '.JText::_( 'NBEVENTMAP_VILLE_FILTRE' ).' --' );
				foreach($this->get('listville') as $temp) {
					$filtrevilles[] = JHTML::_('select.option', $temp->ville );
				}

		$filtredepartements = array();
		$filtredepartements[] = JHTML::_('select.option', '-- '.JText::_( 'NBEVENTMAP_DEPARTEMENT_FILTRE' ).' --' );
				foreach($this->get('listdepartement') as $temp) {
					$filtredepartements[] = JHTML::_('select.option', $temp->departement );
				}

		$filtrecategories = array();
		$select[] = JHTML::_('select.option', '', '-- '.JText::_( 'NBEVENTMAP_CATEGORIE_FILTRE' ).' --');
		$filtrecategories = JHtml::_('category.options', 'com_nbeventmap');
		$filtrecategories = array_merge($select, $filtrecategories);

		$filter_order		= $mainframe->getUserStateFromRequest( $option.'filter_order',		'filter_order',		'a.ordering',	'cmd' );
		$filter_order_Dir 	= $mainframe->getUserStateFromRequest( $option.'filter_order_Dir', 	'filter_order_Dir', 	'', 											'word');
		$search				= $mainframe->getUserStateFromRequest( $option.'search', 			'search', 				'',												'string' );
		$filtreville 		= $mainframe->getUserStateFromRequest( $option.'filtreville', 		'filtreville', 			'-- '.JText::_( 'NBEVENTMAP_VILLE' ).' --', 		'string' );
		$filtredepartement 	= $mainframe->getUserStateFromRequest( $option.'filtredepartement', 'filtredepartement', 	'-- '.JText::_( 'NBEVENTMAP_DEPARTEMENT' ).' --', 	'string' );
		$filtrecategorie 	= $mainframe->getUserStateFromRequest( $option.'filtrecategorie', 	'filtrecategorie', 		'-- '.JText::_( 'NBEVENTMAP_CATEGORIE' ).' --', 	'string' );

		$lists['ville'] 		= JHTML::_('select.genericlist', $filtrevilles, 'filtreville', 'size="1" class="inputbox" onchange="form.submit()"', 'value', 'text', $filtreville );
		$lists['departement'] 	= JHTML::_('select.genericlist', $filtredepartements, 'filtredepartement', 'size="1" class="inputbox" onchange="form.submit()"', 'value', 'text', $filtredepartement );
		$lists['categorie'] 	= JHTML::_('select.genericlist', $filtrecategories, 'filtrecategorie', 'size="1" class="inputbox" onchange="form.submit()"', 'value', 'text', $filtrecategorie );

		
		$lists['order_Dir'] = $filter_order_Dir;
		$lists['order'] = $filter_order;

		
		$lists['search'] = $search;
		
		$this->assignRef('lists', $lists);
		$this->assignRef('items',	$items);
		$this->assignRef('pageNav', $pageNav);
		$this->assignRef('params', $params);

		parent::display($tpl);

	}

	public static function published($value, $i)
	{
		if (is_object($value)) {
			$value = $value->published;
		}
		$img	= $value ? 'components/com_nbeventmap/views/editlieux/toolbar/tick.png' : 'components/com_nbeventmap/views/editlieux/toolbar/publish_x.png';
		$task	= $value ? 'unpublish' : 'publish';
		$alt	= $value ? JText::_('JPUBLISHED') : JText::_('JUNPUBLISHED');
		$action = $value ? JText::_('JLIB_HTML_UNPUBLISH_ITEM') : JText::_('JLIB_HTML_PUBLISH_ITEM');

		$href = '
		<a href="javascript:void(0);" onclick="return listItemTask(\'cb'. $i .'\',\''. $task .'\')" title="'. $action .'">'.
		'<img src="'.$img.'" alt="'.$alt.'"/>';

		return $href;
	}
}
